home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / fadeflip / texture.h < prev    next >
C/C++ Source or Header  |  1996-11-11  |  6KB  |  178 lines

  1. /*
  2.  * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software for
  6.  * any purpose and without fee is hereby granted, provided that the above
  7.  * copyright notice appear in all copies and that both the copyright notice
  8.  * and this permission notice appear in supporting documentation, and that
  9.  * the name of Silicon Graphics, Inc. not be used in advertising
  10.  * or publicity pertaining to distribution of the software without specific,
  11.  * written prior permission.
  12.  *
  13.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  17.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  22.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25.  *
  26.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
  27.  * Use, duplication, or disclosure by the Government is subject to
  28.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30.  * clause at DFARS 252.227-7013 and/or in similar or successor
  31.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  32.  * Unpublished-- rights reserved under the copyright laws of the
  33.  * United States.  Contractor/manufacturer is Silicon Graphics,
  34.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  35.  *
  36.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37.  */
  38. #include <GL/glu.h>
  39. #include <GL/glx.h>
  40.  
  41. extern "C" {
  42. #include "myimage.h"
  43. };
  44.  
  45. #define DEFAULT_DISPLAY_TYPE        GL_UNSIGNED_BYTE
  46. #define DEFAULT_DISPLAY_FORMAT        GL_RGBA
  47. #define DEFAULT_ALIGNMENT        1
  48. #define DEFAULT_COMPONENTS        4
  49. #define DEFAULT_LEVEL            0
  50.  
  51. #define DEFAULT_ENVIRONMENT        GL_MODULATE
  52.  
  53. #define DEFAULT_MIN_FILTER        GL_LINEAR
  54. #define DEFAULT_MAX_FILTER        GL_LINEAR
  55.  
  56. class texture {
  57.  public:
  58.   texture();
  59.   ~texture();
  60.   
  61.   void open();
  62.  
  63.   void set_display_format(GLenum new_display_format);
  64.   GLenum get_display_format();
  65.  
  66.   void set_display_type(GLenum new_display_type);
  67.   GLenum get_display_type();
  68.  
  69.   void set_alignment(int new_alignment);
  70.   int get_alignment();
  71.  
  72.   void set_components(int new_components);
  73.   int get_components();
  74.  
  75.   void set_level(int new_level);
  76.   int get_level();
  77.  
  78.   void set_environment(GLenum new_environment);
  79.   GLenum get_environment();
  80.  
  81.   void set_min_filter(GLenum new_min_filter);
  82.   GLenum get_min_filter();
  83.   void set_max_filter(GLenum new_max_filter);
  84.   GLenum get_max_filter();
  85.  
  86.   int get_width();
  87.   int get_height();
  88.  
  89.   void create_color(int total_size,
  90.             float r, float g, float b, float a, float l);
  91.   void create_checkerboard(int total_size, int block_size,
  92.                float r1 = 1.0, float g1 = 0.0, float b1 = 0.0,
  93.                float alpha1 = 1.0, float lum1 = 0.299,
  94.                float r2 = 0.0, float g2 = 0.0, float b2 = 1.0,
  95.                float alpha2 = 1.0, float lum2 = 0.114);
  96.   void create_diag_stripes(int total_size, int stripe_width,
  97.                float r1 = 1.0, float g1 = 0.0, float b1 = 0.0,
  98.                float alpha1 = 1.0, float lum1 = 0.299,
  99.                float r2 = 0.0, float g2 = 0.0, float b2 = 1.0,
  100.                float alpha2 = 1.0, float lum2 = 0.114);
  101.   void create_from_file(char *fname);
  102.  
  103.   void map_lum_to_alpha();
  104.  
  105.   void draw_pixels();
  106.   void draw_pixels(int x1, int y1, int x2, int y2);
  107.  
  108.   /* setup_texture() sets up the alignment etc */
  109.   void setup_texture();
  110.   void setup_texture(int x1, int y1, int x2, int y2);
  111.  
  112.   /* specify_texture():
  113.    * 1. Calls setup_texture()
  114.    * 2. Calls glTexImage2D() with a level of level if min_filter is 
  115.    * GL_NEAREST or GL_LINEAR, otherwise calls gluBuild2DMipmaps() */
  116.   void specify_texture();
  117.   void specify_texture(int x1, int y1, int x2, int y2);
  118.  
  119.   /* specify_mipmap()
  120.    * Calls glTexImage2D() with a level of level */
  121.   void specify_mipmap();
  122.   void specify_mipmap(int x1, int y1, int x2, int y2);
  123.  
  124.   void pixels_free();
  125.  
  126.  private:
  127.   void pixels_alloc();
  128.   void pixels_alloc(int size);
  129.  
  130.   void assign_pixel(int x, int y, float r, float g, float b, float a,
  131.             float l);
  132.   void assign_pixel(int x, int y, float r, float g, float b, float a,
  133.             float l, GLenum display_format,
  134.             GLenum display_type, int alignment);
  135.  
  136.   inline void assign_pixel_a(int x, int y, float a);
  137.  
  138.   void reformat(GLenum new_display_format, GLenum new_display_type,
  139.         int new_alignment);
  140.  
  141.   int row_length();
  142.   int row_length(GLenum display_format, GLenum display_type, 
  143.          int alignment);
  144.  
  145.   inline float pixel_r(int x, int y);
  146.   inline float pixel_r(int x, int y, GLenum display_format,
  147.                GLenum display_type, int alignment);
  148.  
  149.   inline float pixel_g(int x, int y);
  150.   inline float pixel_g(int x, int y, GLenum display_format,
  151.                GLenum display_type, int alignment);
  152.  
  153.   inline float pixel_b(int x, int y);
  154.   inline float pixel_b(int x, int y, GLenum display_format,
  155.                GLenum display_type, int alignment);
  156.  
  157.   inline float pixel_alpha(int x, int y);
  158.   inline float pixel_alpha(int x, int y, GLenum display_format,
  159.                GLenum display_type, int alignment);
  160.  
  161.   inline float pixel_lum(int x, int y);
  162.   inline float pixel_lum(int x, int y, GLenum display_format,
  163.              GLenum display_type, int alignment);
  164.  
  165.   int height, width;
  166.   GLvoid *pixels;
  167.   int pixels_size;
  168.   GLenum display_format;
  169.   GLenum display_type;
  170.   int alignment;
  171.   int components;
  172.   int level;
  173.  
  174.   GLenum environment;
  175.  
  176.   GLenum min_filter, max_filter;
  177. };
  178.